package com.gcxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;


import com.gcxy.dto.position.PositionInfoDTO;
import com.gcxy.service.PositionService;
import com.gcxy.entity.Position;
import com.gcxy.mapper.PositionMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gcxy.utils.BeanCopyUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Huang先森
 * @since 2024-07-22
 */
@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements PositionService {

    @Resource
    private PositionMapper positionMapper;

    /**
     * 新建岗位
     *
     * @param positionInfoDTO
     * @return
     */
    @Override
    public Integer insertPosition(PositionInfoDTO positionInfoDTO) {
        Position position = BeanCopyUtil.copy(positionInfoDTO, Position.class);
        int row = positionMapper.insert(position);
        return row;
    }

    /**
     * 根据岗位名称获取岗位信息
     *
     * @param name
     * @return
     */
    @Override
    public Position getPositionInfoByName(String name) {
        LambdaQueryWrapper<Position> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Position::getName, name);
        Position position = getOne(queryWrapper);
        return ObjectUtils.isEmpty(position) ? null : position;
    }
}
